﻿using WebApp.BLL;
using WebApp.Web.Core.Auth;
using WebApp.BLL.Manage;
using WebApp.Common;
using WebApp.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApp.Web.Core;

namespace kzjd.rycp.WebApp.Areas.Manage.Controllers
{
    public class UserlogController : Controller
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger("WebApp.Log");

        [AuthorizeFilter("Manage.Userlog")]
        // GET: Manage/Userlog
        public ActionResult List()
        {
            ViewBag.CanEdit = UserAuthBLL.HasAuth("Manage.Userlog.Edit");
            ViewBag.Opartypelist = new SelectList(CommonStr.EnumToList(typeof(enmOprtType)), "key", "value");
            return View();
        }

        [AuthorizeFilter("Manage.Userlog")]
        public JsonResult UserlogListJson(int page, int rows, string s,string fromsearchdate,string tosearchdate, string type, string sort, string order)
        {
            S_user_logService userlogService = new S_user_logService();
            //S_customerService customerService=new S_customerService ();
            //S_departmentService deptService = new S_departmentService();
            S_userService userService = new S_userService();
            Dictionary<string, object> result = new Dictionary<string, object>();
            int rowscount = 0;
            int opartype = Utils.NvInt(type);
            var list = userlogService.PageList(page, rows, opartype, fromsearchdate, tosearchdate, s, sort, order, out rowscount).Select(p => new
            {
                p.Id,
                Oprttype = CommonStr.GetEnumName(typeof(enmOprtType), Utils.NvInt(p.Oprttype)).ToString(),
                p.User_id,
                p.Username,
                //Custname = userService.GetCustname(p.User_id),
                Custname = "",
                Oprttime = p.Oprttime.ToString("yyyy-MM-dd HH:mm:ss"),
                p.Ipaddress,
                p.Comments
            });
            result.Add("total", rowscount);
            result.Add("rows", list);

            return Json(result);
        }


        #region 删除

        [AuthorizeFilter("Manage.Userlog.Edit")]
        public JsonResult Delete(string ids)
        {
            try
            {
                new S_user_logService().DeleteByIds(ids);

                return Json(new AjaxResult("0", CSMSLang.Get("message_delete_success")));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return Json(new AjaxResult(AjaxResult.RESULT_ERROR, ex.Message));
            }
        }

        #endregion

    }
}